﻿using eDoctor.SDK.WeChat.Enum;
using eDoctor.SDK.WeChat.Request;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Web.Areas.Mobile.Controllers
{
    public class WeChatController : Controller
    {
        public ActionResult SyncMenu()
        {
            var site = new Admin.Lib.Site();
            var token = site.GetAccessToken();
            var wechatCall = new eDoctor.SDK.WeChat.Call(token);
            wechatCall.DeleteMeun();

            var domain = System.Configuration.ConfigurationManager.AppSettings["SiteDomain"];
            var result = wechatCall.CreateMenu(new List<Menu>
            {
                new Menu(MenuType.view, "大众评分", domain+"mobile/user/auth?redirectUrl=_mobile_survey_mark"),
                //new Menu(MenuType.view, "有奖调研", domain+"mobile/user/auth?redirectUrl=_mobile_survey_answer"),
                //new Menu(MenuType.view, "参赛选手", domain+"mobile/user/auth?redirectUrl=_mobile_survey_playerlist"),
            });
            return SuccessMsg(result.errcode + result.errmsg);
        }

        protected JsonResult ErrorMsg(string errmsg)
        {
            return this.ErrorMsg<string>(errmsg, null);
        }
        protected JsonResult ErrorMsg<T>(string errmsg, T data)
        {
            return Json(new
            {
                status = 0,
                errmsg = errmsg,
                data = data
            }, JsonRequestBehavior.AllowGet);
        }
        protected JsonResult SuccessMsg()
        {
            return this.SuccessMsg<string>(null);
        }
        protected JsonResult SuccessMsg<T>(T data)
        {
            return Json(new
            {
                status = 1,
                errmsg = "ok",
                data = data
            }, JsonRequestBehavior.AllowGet);
        }
    }
}
